from abc import ABC, abstractmethod
from typing import Tuple, List, Dict
from pathlib import Path
import os

class BaseDocumentParser(ABC):
    """文档解析器基类"""
    
    def __init__(self, config: dict):
        self.config = config
        self.supported_formats = config['document']['supported_formats']
    
    def validate_file(self, file_path: str) -> bool:
        """验证文件格式是否支持"""
        ext = os.path.splitext(file_path)[1].lower()
        return ext in self.supported_formats
    
    @abstractmethod
    def extract_text(self, file_path: str) -> str:
        """提取文本内容"""
        pass
    
    @abstractmethod
    def extract_images(self, file_path: str) -> List[Dict]:
        """提取图片，返回图片信息列表
        Returns:
            List[Dict]: [
                {
                    'image_data': bytes,  # 图片二进制数据
                    'format': str,        # 图片格式
                    'page': int,          # 页码
                    'index': int          # 图片序号
                }
            ]
        """
        pass 